#include "raylib.h"
#include <cmath>


int main() {
    const int screenWidth = 800;
    const int screenHeight = 600;
    
    InitWindow(screenWidth, screenHeight, "Growing Ball Animation");
    SetTargetFPS(120);

    // 小球属性
    Vector2 ballPosition = {100, 300};
    Vector2 ballVelocity = {3, 3};
    float ballRadius = 10.0f;
    float minRadius = 10.0f;
    float maxRadius = 50.0f;
    float scaleSpeed = 0.5f;
    float currentScale = 1.0f;
    bool growing = true;
    
    Color ballColor = RED;
    
    while (!WindowShouldClose()) {
        // 更新小球位置
        ballPosition.x += ballVelocity.x;
        ballPosition.y += ballVelocity.y;
        // 更新小球大小（脉动效果）
        if (growing) {
            currentScale += scaleSpeed * GetFrameTime();
            if (currentScale >= 20.0f) growing = false;
        } else {
            currentScale -= scaleSpeed * GetFrameTime();
            if (currentScale <= 0.5f) growing = true;
        }
        
        // 计算实际半径
        float actualRadius = ballRadius * currentScale;
        // 边界检测和反弹
        if (ballPosition.x - actualRadius <= 0 || ballPosition.x + actualRadius >= screenWidth) {
            ballVelocity.x = -ballVelocity.x;
        }
        if (ballPosition.y - actualRadius <= 0 || ballPosition.y + actualRadius >= screenHeight) {
            ballVelocity.y = -ballVelocity.y;
        }
        

        
        BeginDrawing();
        ClearBackground(RAYWHITE);
        
        // 绘制小球
        DrawCircleV(ballPosition, actualRadius, ballColor);
        
        // 显示信息
        DrawText("Growing and Moving Ball", 10, 10, 20, DARKGRAY);
        DrawText(TextFormat("Position: (%.1f, %.1f)", ballPosition.x, ballPosition.y), 10, 40, 20, DARKGRAY);
        DrawText(TextFormat("Radius: %.1f", actualRadius), 10, 70, 20, DARKGRAY);
        
        EndDrawing();
    }
    
    CloseWindow();
    return 0;
}